
<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" size="tiny" class="wrap">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		 <div class="bt">新增节日</div>
		 <el-form label-width="100px" class="form">
		 <el-form-item label="节假日名称">
 			<el-input v-model="vjjrmc"  placeholder="请输入节假日名称" class="select-block"></el-input>
 			</el-form-item>

		 <el-form-item label="节假日日期">
		 	<el-date-picker v-model="vrq1" type="date" placeholder="开始日期" @keyup.enter.native="search" icon="search" style='width: 42%;float: left;'></el-date-picker>
		 	<el-date-picker v-model="vrq2" type="date" placeholder="结束日期" @keyup.enter.native="search" icon="search" style='width: 42%;float: left;'></el-date-picker>
 		    <span style="color: red;float: left;">注：添加或修改节假日，将会自动影响全校课表的变化</span>	
		 </el-form-item>

		 <el-form-item label="说明">
 			<el-input v-model="vsm"  type="textarea" :rows="4" placeholder="请输入说明" class="select-block"></el-input>
 			</el-form-item>

		</el-form>
		<div class="an" style="text-align: center;">
		<el-button type="primary" class="submit" @click="submit">添加</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		data() {
			return {
				vjjrmc: '',
				vrq1: '',
				vrq2: '',
				vsm: '',
				dialogTableVisible: true
			}
		},
		methods: {
			submit() {
				//检测
				 this.$store.state.loading = true;
			    if(!this.vjjrmc) {
					this.$message.warning('请填写节日名称');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vrq1) {
					this.$message.warning('请选择开始时间');
					this.$store.state.loading = false;
					return;
				}
				else if(!this.vrq2) {
					this.$message.warning('请选择结束时间');
					this.$store.state.loading = false;
					return;
				}
				var logininfo = JSON.parse(localStorage.logininfo);
				var time1 = this.$.getLocalTimeNo0(Date.parse(this.vrq1));
				var time2 = this.$.getLocalTimeNo0(Date.parse(this.vrq2));
				var time3 = (time1+"--"+time2)
				var params3 = qs.stringify({
	    			jjrmc: this.vjjrmc,
	    			rq: time3,
	    			sm: this.vsm,		
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'jjr/add', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
							
						} else {
						this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.form {
		text-align: center;
		margin-top:20px;
	}
	 .select-block {
 		display: block;
 		width: 85%;
 	}
		.input {
			display: inline-block;
		}
		.submit {
			width: 120px;
		}
	}
</style>
